package wifiunion.com.notice.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import wifiunion.com.notice.Constants;
import wifiunion.com.notice.GlideCircleTransform;
import wifiunion.com.notice.R;
import wifiunion.com.notice.entity.NoticeUserList;

/**
 * 通知列表适配器
 */

public class NoticeUserAdapter extends RecyclerView.Adapter<NoticeUsreListViewHolder> {

    private Context mContext;

    private List<NoticeUserList> data = new ArrayList<NoticeUserList>();


    public NoticeUserAdapter(Context context, int type, List<NoticeUserList> dt) {
        mContext = context;
        mType = type;
        data = dt;

    }

    /**
     * 0 listview
     * 1 gridview
     */
    private int mType;

    @Override
    public NoticeUsreListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view;

        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.notice_member_list_item, parent, false);


        NoticeUsreListViewHolder cv = new NoticeUsreListViewHolder(view, mType);


        return cv;
    }

    @Override
    public void onBindViewHolder(NoticeUsreListViewHolder holder, int position) {


        NoticeUserList userinfo = data.get(position);
        if (mType == 0) {


            if (!"0".equals(userinfo.getUuid())) {
                holder.mNoticeMemberNametv.setText(userinfo.getName());
//                holder.mNoticeMembergerdertv.setText(userinfo.getSex() == 1 ? "男" : "女");


//                0:未知
//                1:男
//                2:女

                if (userinfo.getSex() == 1) {
                    holder.mNoticeMembergerdertv.setText("男");
                } else if (userinfo.getSex() == 2) {
                    holder.mNoticeMembergerdertv.setText("女");
                } else {
                    holder.mNoticeMembergerdertv.setText("未知");
                }

                holder.mNoticeMembermobiletv.setText(userinfo.getPhone());
                holder.mNoticeMemberGrouptv.setText(userinfo.getGroupName());
                holder.mNoticeMemberStatetv.setText(userinfo.getAlarmState() == 0 ? "正常" : "告警");

                Glide.with(mContext).load(Constants.HTTP_URL_IMAGESERVER + data.get(position).getShowPic()).placeholder(R.drawable.mr_head)
                        .error(R.drawable.mr_head).fitCenter().into(holder.mNoticeMemberhead1iv);

                Glide.with(mContext).load(Constants.HTTP_URL_IMAGESERVER + data.get(position).getComparisonPic()).placeholder(R.drawable.mr_head)
                        .error(R.drawable.mr_head).transform(new GlideCircleTransform(mContext)).fitCenter().into(holder.mNoticeMemberhead2iv);
            } else {
                Glide.with(mContext).load(R.drawable.msr).placeholder(R.drawable.msr)
                        .error(R.drawable.msr).fitCenter().into(holder.mNoticeMemberhead1iv);

                Glide.with(mContext).load(R.drawable.msr).placeholder(R.drawable.msr)
                        .error(R.drawable.msr).fitCenter().into(holder.mNoticeMemberhead2iv);

                holder.mNoticeMemberNametv.setText("未登记人员");
                holder.mNoticeMembergerdertv.setText("");
                holder.mNoticeMembermobiletv.setText("");
                holder.mNoticeMemberGrouptv.setText("");
                holder.mNoticeMemberStatetv.setText("");

            }


        }


    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
